﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.BLL;

public partial class admin_infomation_user_collect_list : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string layerid = Request["layerid"];
            this.PopedomValidate(layerid, QUERY);
            this.headers.Text = new ColumnBll().LayeridColumnConNaiv(layerid);//内容
            showindex();
            
        }
    }
    //单行删除
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        this.PopedomValidate(layerid, DEL);
        ArticleCollection act = new ArticleCollection();
        GridView gv = (GridView)sender;
        int id = int.Parse(gv.DataKeys[e.RowIndex].Value.ToString());
        bool bo = act.Delete(id);
        if (bo == true)
        {
            Response.Write("<script>alert('删除成功!')</script>");
            showindex();
        }
        else
        {
            Response.Write("<script>alert('删除失败!')</script>");
        }
    }
    //分页数据
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        DataSet ds = new ArticleCollection().GetCollectionList(0, 0);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
    //第一页
    protected void btnFirst_Click1(object sender, EventArgs e)
    {
        this.GridView1.PageIndex = 0;
        showindex();
    }
    //上一页
    protected void btnPrev_Click(object sender, EventArgs e)
    {
        if (this.GridView1.PageIndex != 0)
        {
            this.GridView1.PageIndex = this.GridView1.PageIndex - 1;
            showindex();
        }
        else
        {
        }
    }
    //下一页
    protected void btnNext_Click(object sender, EventArgs e)
    {
        if (this.GridView1.PageIndex != this.GridView1.PageCount - 1)
        {
            this.GridView1.PageIndex = this.GridView1.PageIndex + 1;
            showindex();
        }
        else
        {
        }
    }
    //最后一页
    protected void btnLast_Click(object sender, EventArgs e)
    {
        this.GridView1.PageIndex = this.GridView1.PageCount - 1;
        showindex();
    }
    //前往*页
    protected void btnGo_Click(object sender, EventArgs e)
    {
        try
        {
            int pa = int.Parse(this.txtNewPageIndex.Text.ToString());
            if (1 <= pa || pa <= this.GridView1.PageCount)
            {
                this.GridView1.PageIndex = pa - 1;
                showindex();
            }
            else
            {
                Response.Write("<script>alert('请输入正确的页码!')</script>");
                this.txtNewPageIndex.Text = (this.GridView1.PageIndex + 1).ToString();
            }
        }
        catch (Exception ex)
        {
        }
    }
    //分页数据显示
    protected void showindex()
    {
        DataSet ds = new ArticleCollection().GetCollectionList(0, 0);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        int num = ds.Tables[0].Rows.Count;

        int index = this.GridView1.PageIndex + 1;
        int cont = this.GridView1.PageCount;
        this.label1.Text = "当前第" + index.ToString() + "页    共" + cont.ToString() + "页";
        this.label2.Text = "共" + num.ToString() + "条数据";
        this.txtNewPageIndex.Text = index.ToString();
        if (GridView1.Rows.Count == 0)
        {
            DataTable dt = new DataTable();//COLLECTION_ID
            dt.Columns.Add("COLLECTION_ID");
            dt.Columns.Add("MEMBER_NICKNAME");
            dt.Columns.Add("TITLE");
            dt.Columns.Add("ADD_TIME");
            dt.Rows.Add(dt.NewRow());
            GridView1.DataSource = dt;
            GridView1.DataBind();
            int columncount = dt.Columns.Count;
            GridView1.Rows[0].Cells.Clear();
            GridView1.Rows[0].Cells.Add(new TableCell());
            GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
            GridView1.Rows[0].Cells[0].Text = "没有相关信息";
            GridView1.Rows[0].Cells[0].Style.Add("text-align", "center");
        }
        if (this.GridView1.PageCount != 1)
        {
            this.pages.Visible = true;
            if (this.GridView1.PageIndex == 0)
            {
                btnFirst.Visible = false;
                btnPrev.Visible = false;
                btnNext.Visible = true;
                btnLast.Visible = true;
            }
            else if (this.GridView1.PageIndex == this.GridView1.PageCount - 1)
            {
                btnFirst.Visible = true;
                btnPrev.Visible = true;
                btnNext.Visible = false;
                btnLast.Visible = false;
            }
            else
            {
                btnFirst.Visible = true;
                btnPrev.Visible = true;
                btnNext.Visible = true;
                btnLast.Visible = true;
            }
        }
        else
        {
            btnFirst.Visible = false;
            btnPrev.Visible = false;
            btnNext.Visible = false;
            btnLast.Visible = false;
            btnGo.Visible = false;
            label1.Visible = false;
            label2.Visible = false;
            txtNewPageIndex.Visible = false;
            this.pages.Visible = false;
        }
    }
    //批量选择检查
    private string GetSelIDlist()
    {
        string idlist = "";
        bool BxsChkd = false;
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            CheckBox checkbox = (CheckBox)GridView1.Rows[i].FindControl("DeleteThis");
            if (checkbox != null && checkbox.Checked == true)
            {
                BxsChkd = true;
                idlist += GridView1.Rows[i].Cells[1].Text + ",";
            }
        }
        if (BxsChkd)
        {
            idlist = idlist.Substring(0, idlist.LastIndexOf(","));
        }
        return idlist;
    }
}
